﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<OneDollarStore.Models.ShoppingCartViewModel>" %>

<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
    Giỏ hàng
</asp:Content>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function handleUpdate(context)
        {
            var json = context.get_data();
            var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
            $('#row-' + data.DeletedID).fadeOut('slow');
            $('#cart-summary').html('Cart (<strong>' + data.CartCount + '</strong>)');
            $('#update-message').text(data.Message);
            $('#cart-total').text(data.CartTotal);
        }
    </script>
    <div class="right">
        <div style="margin-left:5px; font-size:15px">
            <h2>Review your cart</h2>
            <div class="button">
                <%= Html.ActionLink("Thanh toán >>", "AddressAndPayment", "Checkout") %>
            </div>
            <div id="update-message"></div>
            <br />
                <table border="1" frame="box" rules="all" style="width:98.6%">
                    <tr>
                        <th>Tên</th>
                        <th>Giá (/1SP)</th>
                        <th>Số lượng</th>
                        <th>Ghi chú</th>
                    </tr>
                    <% foreach (var item in Model.CartItems)
                       { %>
                        <tr id="row-<%= item.RecordID %>">
                            <td style="text-align:center">
                                <%= Ajax.ActionLink(item.SerialProduct.Name, "Details", "Product", new { id = item.SerialProduct.SerialProductID }, null) %>
                            </td>
                            <td style="text-align:center">
                                <% if (String.IsNullOrEmpty(item.SerialProduct.PromotionPrice.ToString()) ||
                                       ((!String.IsNullOrEmpty(item.SerialProduct.PromotionPrice.ToString())) && (DateTime.Now.Date > item.SerialProduct.PromotionEndDate)))
                                   { %>
                                    <%= item.SerialProduct.RetailPrice%>
                                <% }
                                   else
                                   { %>
                                    <%= item.SerialProduct.PromotionPrice%>
                                <% } %>
                            </td>
                            <td style="text-align:center">
                                <%= item.Count %>
                            </td>
                            <td style="text-align:center">
                                <%= Ajax.ActionLink("Xóa ", "RemoveFromCart", new { id = item.RecordID }, new AjaxOptions { OnSuccess = "handleUpdate" }) %>
                            </td>
                        </tr>
                    <% } %>
                    <tr>
                        <td align="right" style="padding-right: 10px">
                            <b>Tổng tiền</b>
                        </td>
                        <td id="cart-total" colspan="3" align="center">
                            <%= Model.CartTotal %>
                        </td>
                    </tr>
                </table>
            <br style="clear:both"/>
            <div>
                <%= Html.ActionLink("Tiếp tục mua", "Index", "Product") %>
            </div>
        </div>
    </div>
</asp:Content>